package com.dreamtour.mapper;

import com.dreamtour.DTO.DailyTransactionDTO;
import com.dreamtour.entity.Transactions;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xls
 * @since 2024-12-24
 */
public interface TransactionsMapper extends BaseMapper<Transactions> {
    @Select("SELECT " +
            "    DATE(finishTime) AS transactionDay, " +
            "    COUNT(*) AS transactionCount, " +
            "    COALESCE(SUM(transactionAmount), 0) AS transactionAmount " +
            "FROM Transactions " +
            "WHERE finishTime >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) " +
            "GROUP BY DATE(finishTime) " +
            "ORDER BY transactionDay")
    List<DailyTransactionDTO> getDailyTransactionStats();
}
